/*
 * @Author: 273198238 2412069378@qq.com
 * @Date: 2025-03-14 09:19:55
 * @LastEditors: 273198238 2412069378@qq.com
 * @LastEditTime: 2025-03-17 09:20:06
 * @FilePath: \population\src\store\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    populationData: [
      { name: "北京", inflow: 0, outflow: 0 },
      { name: "上海", inflow: 0, outflow: 0 },
      { name: "广州", inflow: 0, outflow: 0 },
      { name: "深圳", inflow: 0, outflow: 0 },
    ],
    
  },
  getters: {
    // getPopulationData(state) {
    //   return state.populationData;
    // },
  },
  mutations: { 
    updatePopulation(state) {
    const cities = ["北京", "上海", "广州", "深圳"];
    state.populationData.forEach(cityData => {
      if (cities.includes(cityData.name)) {
        cityData.inflow = Math.floor(Math.random() * 1000);
        cityData.outflow = Math.floor(Math.random() * 1000);
      }
    });
  },
  },
  actions: {
    updatePopulation({ commit }) {
      setInterval(() => {
        commit("updatePopulation");
      }, 3000);

  },
  },
  modules: {},
});
